/*
 * @Author: zzuisa 
 * @Date: 2018-04-23 18:20:52 
 * @Last Modified by: zzuisa
 * @Last Modified time: 2018-04-23 21:21:22
 */
const path = require('path');
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin')


const config = {
  entry: './src/app.jsx',
  output: {
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/dist/',
    filename: 'js/app(webpack).js'
  },
  module: {
    //react(jsx)语法的处理
  rules: [
    {
      test: /\.jsx$/,
      exclude: /(node_modules)/,
      use: {
           loader: 'babel-loader',
           options: {
           presets: ['env','react']
        }
      }
    },
  //css文件的处理
    {
             test: /\.css$/,
             use: ExtractTextPlugin.extract({
              fallback: "style-loader",
              use: "css-loader"
            })
    },
    //sass文件的处理
    {
      test: /\.scss$/,
      use: ExtractTextPlugin.extract({
        fallback: 'style-loader',
        use: ['css-loader', 'sass-loader']
      })
    },
    //图片的配置
    {
      test: /\.(png|jpg|gif)$/,
      use: [
        {
          loader: 'url-loader',
          options: {
            limit: 8192,
            name:'resource/[name].[ext]'  //指定路径
          }
        }
      ]
    },
    //字体图标的配置
    {
      test: /\.(eot|svg|ttf|woff|woff2|otf)$/,
      use: [
        {
          loader: 'url-loader',
          options: {
            limit: 8192,
            name:'resource/[name].[ext]'  //指定路径
          }
        }
      ]
    }
    ]
  },
  
  plugins: [
    //处理html文件
    new HtmlWebpackPlugin({
      template:'./src/index.html'
    }),
    //独立css文件
    new ExtractTextPlugin("css/[name].css"),
    //提出公共模块
    new webpack.optimize.CommonsChunkPlugin({
      name: 'common',
      filename: 'js/base.js'
    })
  ],
  devServer: {
    port:8888
       },
};
module.exports = config;